//package com.play.ballen.home.dialog;
//
//import android.content.DialogInterface;
//import android.content.pm.ActivityInfo;
//import android.graphics.drawable.ColorDrawable;
//import android.os.Bundle;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.view.Window;
//import android.view.WindowManager;
//
//import androidx.annotation.NonNull;
//import androidx.annotation.Nullable;
//import androidx.fragment.app.DialogFragment;
//import androidx.fragment.app.FragmentManager;
//
//import com.play.ballen.R;
//
//import org.kymjs.chat.widget.KJChatKeyboard;
//
///**
// * 设备选择弹框
// *
// * 使用DialogFragment
// *  DialogFragment可以加载Fragment
// *  PopupWindow不可以加载Fragment
// */
//public class PreviewDeviceDialog extends DialogFragment implements View.OnClickListener {
//
//    private int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; //默认竖屏
//    KJChatKeyboard kjChatKeyboard;
//    FragmentManager fragmentManager;
//    @Override
//    public void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        //设置对话框的风格和各种属性
//        setCancelable(true);
//        //setStyle();
//    }
//
//    @Nullable
//    @Override
//    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        //设置布局相关
//        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); //不显示弹框title
//
//        //设置默认布局位置
//        Window window = this.getDialog().getWindow();
//        window.getDecorView().setPadding(0, 0, 0, 0); //去掉dialog默认的padding
//        window.setBackgroundDrawable(new ColorDrawable());
//
//        //layout
//        View view = inflater.inflate(R.layout.fragment_dialog_comment, container, false);
////
////        kjChatKeyboard = view.findViewById(R.id.chat_msg_input_box);
//
//
//        // 在DialogFragment中使用getChildFragmentManager()添加Fragment
//        CommentFragment yourFragment = new CommentFragment();
//        getChildFragmentManager().beginTransaction()
//                .replace(R.id.frag, yourFragment)
//                .commit();
//
////        kjChatKeyboard.setOnOperationListener(new OnOperationListener() {
////            @Override
////            public void send(String content) {
////
////            }
////
////            @Override
////            public void selectedFace(Faceicon content) {
////
////            }
////
////            @Override
////            public void selectedEmoji(Emojicon emoji) {
////                kjChatKeyboard.getEditTextBox().append(emoji.getValue());
////            }
////
////            @Override
////            public void selectedBackSpace(Emojicon back) {
////                DisplayRules.backspace(kjChatKeyboard.getEditTextBox());
////            }
////
////            @Override
////            public void selectedFunction(int index) {
////
////            }
////        });
//
//
//        initData();
//        return view;
//    }
//
//    public void initData() {
//
//        //加载子Fragment
////        deviceFragment = new DeviceFragment("", new DeviceFragmentListener() {
////            @Override
////            public void setTitle(String title) {
////                //wsToolbarTitle.setText(title);
////            }
////
////            @Override
////            public void backLast() {
////                dismiss();
////            }
////        });
////        getChildFragmentManager()
////                .beginTransaction()
////                .replace(R.id.container, deviceFragment, "Sub")
////                .commit();
//    }
//
//    @Override
//    public void onClick(View view) {
//        switch (view.getId()) {
////            case R.id.tv_back:
////                deviceFragment.onBackPressed();
////                break;
////            case R.id.tv_confirm:
////                break;
//        }
//    }
//
//    @Override
//    public void onResume() {
//        super.onResume();
//        //必须在onResume时候重绘高度和动画才可以实现效果
//
////        if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { //竖屏
//            Window window = this.getDialog().getWindow();
//            WindowManager.LayoutParams lp = window.getAttributes();
//            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//            int screenHeight = getResources().getDisplayMetrics().heightPixels;
//            lp.height = Math.round(screenHeight * 2 / 3);
//            lp.gravity = Gravity.BOTTOM; //设置dialog的位置在底部
//            lp.windowAnimations = R.style.AnimDownToTop; //设置底部动画
//            window.setAttributes(lp);
////        }
////        else {//横屏
////            Window window = this.getDialog().getWindow();
////            WindowManager.LayoutParams lp = window.getAttributes();
////            int screenWidth = getResources().getDisplayMetrics().widthPixels;
////            lp.width = Math.round(screenWidth / 2);
////            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
////            lp.gravity = Gravity.RIGHT; //设置dialog的位置在底部
////            lp.windowAnimations = R.style.AnimRightToLeft; //设置右侧动画
////            window.setAttributes(lp);
////        }
//    }
//
//    public void show(FragmentManager fragmentManager, int orientation) {
//        if(this.orientation == orientation) { //相同方向，重新打开，直接展示弹框（getDialog().show()），不重走生命周期（show）
//            if(this.isAdded()) {
//                getDialog().show(); //如果是显示，则说明目前状态是hide，直接显示
//            } else {
//
//                show(fragmentManager, "DeviceSelect");
//
//            }
//        } else { //不同方向，则重新走生命周期
//            //设置新方向
//            this.orientation = orientation;
//            //调用dismiss后，再次调用show生命周期会重新走一遍
//            dismiss();
//        }
//    }
//
//    //直接调用onDismiss，整个弹框会被销毁，再次调用show会重新走生命周期
//    @Override
//    public void onDismiss(@NonNull DialogInterface dialog) {
//        //仅调用hide，不销毁，仅隐藏
//        getDialog().hide();
//    }
//}
